'''
Description: 
Author: Zilu
Date: 2021-11-09 14:06:28
Version: 
LastEditTime: 2021-11-09 14:15:46
LastEditors: Zilu
'''

# IO操作也可以在内存中读取
from io import StringIO

f = StringIO()
f.write("Hello world")
f.write(' ')
f.write("world!")
print(f.getvalue())

f1 = StringIO("Hello!\nHi!\nGoodbye!")
while 1:
    s = f1.readline()
    if s == '':
        break
    print(s.strip())

# 也可以操作二进制数据
from io import BytesIO
f2 = BytesIO('中文'.encode("utf-8"))
print(f2.getvalue())

# StringIO 和 BytesIO 和文件读写有一致的接口
